﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class SanphamDAL:DataService
    {
        #region[Sanpham_GetByAll]
        public DataTable Sanpham_GetByAll()
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_GetByAll", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Sanpham_GetById]
        public DataTable Sanpham_GetById(string id)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_GetById", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_San_pham", id));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Sanpham_GetByLoai]
        public DataTable Sanpham_GetByLoai(string id)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_GetByLoai", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", id));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Sanpham_GetByTop]
        public DataTable Sanpham_GetByTop(string Top, string Where, string Order)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_GetByTop", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Top", Top));
                cmd.Parameters.Add(new SqlParameter("@Where", Where));
                cmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion

        #region[Sanpham_Insert]
        public void Sanpham_Insert(SanphamInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_Insert", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_San_pham", data.Ma_San_pham));
                cmd.Parameters.Add(new SqlParameter("@Ten_San_pham", data.Ten_San_pham));
                cmd.Parameters.Add(new SqlParameter("@Hinh_Minh_hoa", data.Hinh_Minh_hoa));
                cmd.Parameters.Add(new SqlParameter("@Chi_tiet", data.Chi_tiet));
                cmd.Parameters.Add(new SqlParameter("@Gia_ban", data.Gia_ban));
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", data.Ma_Phan_loai));
                cmd.Parameters.Add(new SqlParameter("@Ngay", data.Ngay));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion

        #region[Sanpham_Update]
        public void Sanpham_Update(SanphamInfo data)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_Update", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_San_pham", data.Ma_San_pham));
                cmd.Parameters.Add(new SqlParameter("@Ten_San_pham", data.Ten_San_pham));
                cmd.Parameters.Add(new SqlParameter("@Hinh_Minh_hoa", data.Hinh_Minh_hoa));
                cmd.Parameters.Add(new SqlParameter("@Chi_tiet", data.Chi_tiet));
                cmd.Parameters.Add(new SqlParameter("@Gia_ban", data.Gia_ban));
                cmd.Parameters.Add(new SqlParameter("@Ma_Phan_loai", data.Ma_Phan_loai));
                cmd.Parameters.Add(new SqlParameter("@Ngay", data.Ngay));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion

        #region[Sanpham_Delete]
        public void Sanpham_Delete(string id)
        {
            using (SqlCommand cmd = new SqlCommand("Sanpham_Delete", getConn()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Ma_San_pham", id));
                cmd.ExecuteNonQuery();
            }
            //return true;
        }
        #endregion
    }
}
